
package it.csttech.date;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

/**
 * This class is meant to map a WebApplicationException into a response
 * 
 * @author marcello.felappi
 * @author marco.dalena
 */
@Provider
public class WebApplicationExceptionMapper
	implements ExceptionMapper<WebApplicationException> {

	/**
	 * This methods is used to translate a WebApplicationException into a
	 * BadRequest response with a json as entity representing a summary of the
	 * exception
	 * 
	 * @param exception
	 *            - WebApplicationException catched by the exception mapper
	 * @return the response representing the thrown exception
	 */
	@Override
	public Response toResponse(WebApplicationException exception) {

		return Response.status(exception.getResponse().getStatus()).type(
			MediaType.APPLICATION_JSON).entity(new ErrorObject(exception)).build();
	}

}
